import axios from 'axios'
import {devServer} from "../../../../vue.config";
axios.defaults.baseURL = '/api'

const roleOptions = [
    {label: '反馈管理员', value: 1},
    {label: '标定管理员', value: 2},
    {label: '普通用户', value: 3},
    {label: '超级管理员', value: 0}
]

const activeOptions = [
    {label: '正常', value: 1},
    {label: '禁用', value: 0}
]

function roleFilter(value) {
    return roleOptions.filter(i => i.value === value)[0].label
}

function activeFilter(value) {
    return activeOptions.filter(i => i.value === value)[0].label
}


const searchFormGroup= [
      {label: '姓名', type: 'input', options: [], width: '150px'}
]


/**
 * 搜索表单设置
 * @rules:  是否验证       {Boolean}
 * @inline: 是否内联       {Boolean}
 * @width:  label宽度     {String}
 * @align:  label对齐方式  {String}
 */
const searchFormSetting = {
    rules: false,
    inline: true,
    ref: 'searchForm',
    width: '70px',
    align: 'right'
}
/**
 * 搜索表单按钮事件
 * @name: 按钮名称
 * @event: 按钮事件名（子组件直接@eventName=handleCustomizeEvent）
 * @primary：按钮类型（按钮的颜色）
 * @icon：按钮的小图标
 */
const searchFormButton = [
    {name: '查询', event: 'search', type: 'primary', icon: 'el-icon-search'},
    {name: '重置', event: 'reset', type: 'info', icon: 'el-icon-refresh-left'},
    {name: '添加记录', event: 'create', type: 'warning', icon: 'el-icon-plus'},
    {name: '删除选中', event: 'delete', type: 'danger', icon: 'el-icon-delete'}
]


/**
 * 表格表头信息
 * @chineseToPinYin: 这是封装的根据中文汉字转换为拼音的方法
 * @prop: 表头字段名
 * @filter: 数据过滤器
 * @label: 表头显示名称
 */

const tableTitle = [
    {prop: 'username', label: '用户名', width: '120'},
    {prop: 'password', label: '密码', width: '300'},
    {prop: 'name', label: '姓名', width: '120'},
    {prop: 'is_active', label: '激活状态',filter: activeFilter, width: '100'},
    {prop: 'role', label: '角色', filter: roleFilter, width: '100'},
    {prop: 'email', label: '邮箱', width: '200'},
    {prop: 'phone', label: '电话', width: '200'},
    {prop: 'last_login', label: '最后登录时间', width: '150'},
    {prop: 'date_joined', label: '加入时间', width: '150'},
]
/**
 * 表格按钮事件
 * @event: 按钮事件名（子组件直接@eventName=handleCustomizeEvent）
 * @primary：按钮类型（按钮的颜色）
 */
const tableButton = [
    {label: '编辑', event: 'edit', type: 'primary'},
    {label: '删除', event: 'delete', type: 'danger'}
]

/**
 * 弹出层表单
 */
const dialogFormSetting = {
    rules: false,
    inline: false,
    ref: 'dialogForm',
    width: '90px',
    align: 'left'
}

const dialogFormGroup = [
    {label: '用户名', type: 'input', required: true},
    {label: '密码', type: 'input', required: true},
    {label: '姓名', type: 'input', required: true},
    {label: '邮箱', type: 'input', required: true},
    {label: '电话', type: 'input', required: true},
    {label: '激活状态', type: 'select', options: activeOptions, required: true, width: '100%'},
    {label: '角色', type: 'select', options: roleOptions, required: true, width: '100%'},
]

const dialogFormButton = [
    {name: '确定', event: 'create', type: 'primary'},
    {name: '取消', event: 'cancel'}
]

const uploadFormSetting = {
    rules: false,
    inline: false,
    ref: 'uploadForm',
    width: '90px',
    align: 'left'
}

const uploadFormGroup = [
    {label: '产品型号', type: 'select', required: true},
    {
        label: '手术上传',
        type: 'upload-drag',
        action: 'http://'+devServer.public+'/api/feedback/surgical/upload/',
        limit: 1,
        tip: '请上手术安排的.xlsx/.xlsm格式文件',
        required: true
    }
]

const uploadFormButton = [
    {name: '确定', event: 'upload', type: 'primary'},
    {name: '取消', event: 'cancel'}
]

export {
    searchFormSetting,
    searchFormButton,
    tableTitle,
    tableButton,
    searchFormGroup,
    dialogFormButton,
    dialogFormGroup,
    dialogFormSetting,
    uploadFormGroup,
    uploadFormButton,
    uploadFormSetting,
    roleOptions
}
